﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using System.Collections.Generic;
using DataAccess;

namespace QuanLyKhachSan
{
    public partial class XrptHoaDonThuePhong : DevExpress.XtraReports.UI.XtraReport
    {
        HoaDonThuePhongManager controller = new HoaDonThuePhongManager();

        public XrptHoaDonThuePhong(string ma)
        {
            InitializeComponent();
            Form_Load(ma);
        }

        private void Form_Load(string ma)
        {
            HoaDonThuePhong list = controller.TimHoaDonTheoDK(hdtp => hdtp.MaHD + "" == ma).Result[0];
            int stt = 1;
            xrlblNgayDen.Text = list.NgayDen.Value.ToShortDateString();
            xrlblNgayDi.Text = list.NgayDi.Value.ToShortDateString();
            decimal tongtien=0;
            xrlblSoTienDaDat.Text = list.TienDatCoc + "";
            xrlblMaHD.Text = list.MaHD+"";
            xrlblNgayLapHD.Text = DateTime.Now.ToShortDateString();
            foreach (var item in list.ChiTietHoaDonThuePhongs)
            {
                XRTableCell cell1 = new XRTableCell();
                XRTableCell cell2 = new XRTableCell();
                XRTableCell cell3 = new XRTableCell();
                XRTableCell cell4 = new XRTableCell();

                cell1.WidthF = 40;
                cell2.WidthF = 160;
                cell3.WidthF = 110;
                cell4.WidthF = 150;

                cell1.Text = stt + ""; stt++;
                cell2.Text = item.KhachHang.HoTenKH;
                cell3.Text = item.SoPhong;
                tongtien+=item.Phong.LoaiPhong.GiaPhong * (decimal)(item.HoaDonThuePhong.NgayDi.Value - item.HoaDonThuePhong.NgayDen.Value).TotalDays;
                cell4.Text = item.Phong.LoaiPhong.GiaPhong * (decimal)(item.HoaDonThuePhong.NgayDi.Value - item.HoaDonThuePhong.NgayDen.Value).TotalDays + "";

                XRTableRow row = new XRTableRow();
                row.Cells.Add(cell1);
                row.Cells.Add(cell2);
                row.Cells.Add(cell3);
                row.Cells.Add(cell4);

                xrTable2.Rows.Add(row);
            }
            xrTable2.Rows[0].Visible = false;
            xrlblTongTien.Text = tongtien + "";
            xrlblSoTienPhaiTra.Text = (tongtien - list.TienDatCoc)+"";
            xrlblNhanVienLeTan.Text = list.NhanVien.TenNhanVien;
            xrlblNguoiThanhToan.Text = list.HoTenNguoiDat;
        }

    }
}
